package com.jar.exercise.equals和等号的区别;

/**
 * java中equals和==的区别
 */
public class Demo1 {
	public static void main(String[] args) {
        
/*
        String s1 = "Monday";
        String s2 = "Monday";
        if (s1 == s2) {
            System.out.println("s1 == s2");
        } else {
            System.out.println("s1 != s2");
        }
*/

    /*
    结果  s1 != s2
    s1 equals s2
    */
       /* String s1 = "Monday";
        String s2 = new String("Monday");
        if (s1 == s2) {
            System.out.println("s1 == s2");
        } else {
            System.out.println("s1 != s2");
        }
        if (s1.equals(s2)) {
            System.out.println("s1 equals s2");
        } else {
            System.out.println("s1 not equals s2");
        }*/
//        String s = "sdf";
//        String s2 = "sdf";
//        System.out.println(s==s2); //true 有字符串常量池
//
//        String s3 = "sdf";
//        String s4 = new String("sdf");
//        Integer se = 1;
//        System.out.println(s3==s4); //false 重新创建了对象
//
//        String s5 = "sdf";
//        String s6 = new String("sdf");
//        System.out.println(s5.equals(s6)); //true String 内部重写了equals方法 判断值是否相同

	}
}

